const app = getApp();
const { AskComponent } = app._require("common/index");

AskComponent({
  properties: {
    show: {
      type: Boolean,
      value: false,
  },
  selectItems:{
    type: Map,
    value: {},
  },
  nameItems:{
    type:String,
    value:""
  },
  item: {
    type: Map,
    value: {},
  },
  approveDesc:{
    type:String,
    value:""
  },
  currentIndex:{
    type:String,
    value:""
  }
  },
  data: {
    showContent:false,
    // show:true
  }, 
  methods: {
    taskApprovalForm(e){
    //  console.log(e);
    let reason = e.detail.value.content;
    let approvedStatus = e.detail.target.dataset.index;
    let taskId = this.data.item.id;
    let parms ={"taskId":taskId,approvedStatus:approvedStatus,reason:reason}
      // console.log(content,approvedStatus,taskId);
    this.approvedTaskAction(parms);
   
    },
    async approvedTaskAction(e){
      // console.log(e)
      let reason = e.reason;
      let approvedStatus = e.approvedStatus;

      let failList = []
      if(approvedStatus==2){
        let dataIds = ""
        for(let key in this.data.selectItems){
            let value = this.data.selectItems[key];
            console.log(value)
            // let dataFormId = value.dataFormId;
            let failList_item = {};
            failList_item= {"dataFormId":value.dataFormId,"verifyCause":""};
            // if(dataIds.length==0){
            //   dataIds = dataFormId;
            // }else{
            //   dataIds = dataIds + ","+dataFormId
            // }
            // console.log(JSON.stringify(failList));
            // failList_item =  JSON.stringify(failList_item);
            failList.push(failList_item);
        }

        if(failList.length>0){
          // failList = JSON.stringify(failList);
          e["failList"]=failList;
          
        }

        // e["dataIds"] = dataIds
     }
      // console.log(JSON.stringify(failList));
      console.log(e)
      // return
      if(reason.length==0&&approvedStatus !=1){
        wx.askShowToastEx({
          title: "请输入驳回原因",
          icon: "none",
          
        })
        return
      }
      this.cancleAction()
    
      const response = await this.$_server("task/approval", {
          data: {
              ...e
          }
      });
      let { data } = response;

      wx.askShowToastEx({
        title: data.message||"操作成功!",
        icon:"none"
      })

      if (data.code !== 200) {
         return
      }
   
      // let currentIndex = this.data.currentIndex;
      this.$emit("actionEnd",e,)
    


  },
     cancleAction:function(e){
        this.setData({
          "show":false,
          "showContent":false
        })
      },
      showAllContentAction(){
        console.log("===");
        this.setData({
          showContent:!this.data.showContent
        })
      }
  },
  
})
